package com.qcby.lxt.framedemo.rest;

import com.qcby.lxt.framedemo.annotation.NoNeedToken;
import com.qcby.lxt.framedemo.entity.Test;
import com.qcby.lxt.framedemo.service.TestService;
import com.qcby.lxt.framedemo.util.AjaxResult;
import com.qcby.lxt.framedemo.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @className: LoginController
 * @description:
 * @author: lxt
 * @create: 2021-04-19 11:11
 **/
@RestController
@RequestMapping("rest/login")
public class RestLoginController {
    @Autowired
    private TestService testService;
    @NoNeedToken
    @GetMapping
    public AjaxResult login(Long userId){

        Test test = testService.getById(userId);
        if(test == null){
            return AjaxResult.error("登录信息不正确");
        }
        //给分配一个token 然后返回
        String jwtToken = JwtUtil.createToken(test.getId(),test.getName());
        test.setToken(jwtToken);
        return AjaxResult.success(test);
    }
}
